﻿$(document).ready(function () {

    var name = $("#name").val();
    layui.use('table', function () {
        var table = layui.table,
            form = layui.form;
        table.render({
            elem: '#test'
            , url: '/Document_wait/Display'
            , cellMinWidth: 80
            , cols: [[
                { field: 'TaskTiltle', width: 190, title: '任务标题' }
                , { field: 'Publisher', width: 80, title: '发布人' }
                , { field: 'TaskContent', title: '任务内容', width: 525 }
                , { field: 'Oneer', width: 80, title: '执行人' }
                , { field: 'CompletionTime', width: 160, title: '发布时间', sort: true, templet: "<div>{{Format(d.CompletionTime,'yyyy-MM-dd hh:mm:ss')}}</div>" }
                , { field: 'Status', title: '是否完成', width: 100, templet: '#switchTpl', unresize: true }
            ]]
            , page: true
            , id: 'testReload'
        });

        //监听启用和禁用操作
        form.on('switch(sexDemo)', function (obj) {
            var tip = "启用";
            var id = this.id;
            var tap = 0;
            //layer.tips(this.id + ' ' + this.value + '：' + obj.elem , obj.othis);
            if (this.value === "0") {
                tip = "保存";
                tap = 1;
                //启用的功能代码
                $.ajax({
                    url: "/Document_wait/Update?id=" + id + "&status=" + tap,
                    type: "Post",
                    success: function (result) {
                        if (result.success) {
                            layer.msg(tip + '成功！', {
                                title: '提示框',
                                icon: 1,
                                time: 2000
                            }, function () {
                                location.reload();//刷新当前页面
                            });
                        }
                        else {
                            layer.msg(tip + '失败！', {
                                title: '提示框',
                                icon: 2,
                                time: 2000
                            });
                        }
                    }
                });
            }
        });
    });

    $("#sele").click(function () {
        TableReload();
    });


    function TableReload() {
        var table = layui.table;
        //获取页面管理员名称和时间
        var Publisher = $("#Publisher").val();
        var TaskTiltle = $("#TaskTiltle").val();
        var CompletionTime = $("#demo").val();
        //上述方法等价于
        table.reload('testReload', {
            where: { //设定异步数据接口的额外参数，任意设
                Publisher: Publisher,
                TaskTiltle: TaskTiltle,
                CompletionTime: CompletionTime
                //…
            }
        });
    };

});